package com.lsy.weizhi2.activity;

import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.widget.LinearLayoutManager;
import android.view.ViewTreeObserver;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lsy.weizhi2.R;
import com.lsy.weizhi2.adapter.CardPicAdapter;
import com.lsy.weizhi2.adapter.MyAblum_Adapter;
import com.lsy.weizhi2.config.MyHeight;
import com.lsy.weizhi2.config.MyInfo;
import com.lsy.weizhi2.mybase.MyBaseActivity;


public class FriendCard extends MyBaseActivity {
    private com.lsy.weizhi2.mybase.MyTitleView mCard_title;
    private ImageView mBashou_1;
    private ImageView mBashou_2;
    private ImageView mCard_image;
    private TextView mCard_name;
    private TextView mCard_renzheng;
    private TextView mCard_classify;
    private TextView mCard_success_num;
    private TextView mCard_danwei;
    private RatingBar mCard_dengji;
    private TextView mCard_jianjie;
    private TextView mTishi;
    private TextView mCard_jubao_num;
    private TextView mPic;
    private android.support.v7.widget.RecyclerView mCard_picture;
    private TextView mDashang;
    private Context context;
    private Handler handler=new Handler();
    private int xx;
    private CardPicAdapter cardPicAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_friend_card);
        context=FriendCard.this;
        bindViews();
    }

    private void bindViews() {

        mCard_title = (com.lsy.weizhi2.mybase.MyTitleView) findViewById(R.id.card_title);
        mBashou_1 = (ImageView) findViewById(R.id.bashou_1);
        mBashou_2 = (ImageView) findViewById(R.id.bashou_2);
        mCard_image = (ImageView) findViewById(R.id.card_image);
        mCard_name = (TextView) findViewById(R.id.card_name);
        mCard_renzheng = (TextView) findViewById(R.id.card_renzheng);
        mCard_classify = (TextView) findViewById(R.id.card_classify);
        mCard_success_num = (TextView) findViewById(R.id.card_success_num);
        mCard_danwei = (TextView) findViewById(R.id.card_danwei);
        mCard_dengji = (RatingBar) findViewById(R.id.card_dengji);
        mCard_jianjie = (TextView) findViewById(R.id.card_jianjie);
        mTishi = (TextView) findViewById(R.id.tishi);
        mCard_jubao_num = (TextView) findViewById(R.id.card_jubao_num);
        mPic = (TextView) findViewById(R.id.pic);
        mCard_picture = (android.support.v7.widget.RecyclerView) findViewById(R.id.card_picture);
        mDashang = (TextView) findViewById(R.id.dashang);
    }

    @Override
    protected void onStart() {
        super.onStart();
        mCard_title.setTitle(MyInfo.CartName);
        LinearLayoutManager manager=new LinearLayoutManager(context);
        manager.setOrientation(LinearLayoutManager.HORIZONTAL);
        cardPicAdapter=new CardPicAdapter(context,null);
        mCard_picture.setLayoutManager(manager);
        mCard_picture.setAdapter(cardPicAdapter);
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    protected void onResume() {
        super.onResume();
        xx=0;
        new Thread(new Runnable() {
            @Override
            public void run() {
                ViewTreeObserver vto = mCard_title.getViewTreeObserver();
                vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                    @Override
                    public void onGlobalLayout() {
                        if (xx < 1) {
                            xx++;
                            handler.post(new Runnable() {
                                @Override
                                public void run() {
                                    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(mCard_title.getLayoutParams());
                                    params.height = MyHeight.ACTIONBAR + MyHeight.MyTitleHeight;
                                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                                        mCard_title.setLayoutParams(params);
                                    }
                                }
                            });
                        }
                    }
                });
            }
        }).start();
    }
}
